package com.example.votemanage.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.votemanage.entity.VoteOption;
import com.example.votemanage.entity.VoteSubject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xingcheng
 * @since 2024-06-06
 */
public interface VoteSubjectMapper extends BaseMapper<VoteSubject> {
    @Select("SELECT * FROM vote_subject WHERE VS_TITLE LIKE CONCAT('%', #{vsTitle}, '%') ORDER BY VS_ID DESC")
    @Results(id="voteSubject", value = {
            @Result(property = "vsId", column = "vs_id"),
            @Result(property = "voteItems", column = "vs_id", many = @Many(select = "com.example.votemanage.mapper.VoteItemMapper.selectByVsId")),
            @Result(property = "voteOptions", column = "vs_id", many = @Many(select = "com.example.votemanage.mapper.VoteOptionMapper.selectByVsId"))
    })
    public IPage<VoteSubject> selectAllVoteSubject(Page<VoteSubject> page, @Param("vsTitle") String vsTitle);
    @Select("SELECT * FROM vote_subject where vs_id = #{vsId}")
    @ResultMap(value = "voteSubject")
    public VoteSubject selectAllSubject(Integer vsId);

}
